
import userDetailPop from './userDetailPop.vue'; //用户信息弹窗
import { destroyView, renderView } from '@/utils/createApp'

const CurrentRenderPop = {}
const ShowPopViews = {
    'userDetail': userDetailPop
}

const createShowPop = (options, popView, type) => {
    const instance = renderView({
        view: popView, 
        body: options?.body || '#app', 
        useclose: true,
        provide: {
            close:(bool)=>{
                destroyView(instance)
                CurrentRenderPop[type] = 0;
                console.log('option,closeFn', bool, options.closeFn)
                if (typeof options.closeFn === 'function') options.closeFn(bool)
            },
            ...(options.provide||{})
        },
        props: {
            ...(options.props||{})
        }
    })
    return instance
}


export const renderUserDetailPop = ( options = {}, type = 'userDetail',) => {
    console.log('=========渲染弹窗==', type, options)
    if (CurrentRenderPop[type]) return
    CurrentRenderPop[type] = 1;
    return createShowPop(options, ShowPopViews[type] || userDetailPop, type)
}

